/**
 * @author：胡鹏
 * @date：2024/11/6
 * 打卡首页
 */
//index.js
import lableAll from "../../utils/mapLable";

const lable = lableAll.getAllLable();
const apiService = require('../../utils/yxqzutil.js'); //接口请求工具
//获取应用实例
const app = getApp();
const urlPositionList = app.globalData.urlPositionList;
const urlWechatMotionAdd = app.globalData.urlWechatMotionAdd;
const urlWechatMotionList = app.globalData.urlWechatMotionList;
const userInfo = wx.getStorageSync('userInfo')
// 暂时写死
const optiondata = {
  openid: userInfo.openid
};

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    additionalOffset: 10,
    showControls: false,
    videos: "cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/WeChat_20250306173526.mp4",
    checkinImageUrl: "cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkInPage/runing2.jpg",
    activityItem: [
      {
        title: "逛公园好去处,逛公园好去处,逛公园好去处,逛公园好去处逛公园好去处,逛公园好去处,逛公园好去处,逛公园好去处",
        posterUrl: "cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/swiper/image1.jpg",
        tag: ["活动", "攻略"]
      },
      {
        title: "清晨跑步攻略",
        posterUrl: "cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/swiper/image2.jpg",
        tag: ["活动", "攻略"]
      },
      {
        title: "逛公园好去处",
        posterUrl: "cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/swiper/image3.jpg",
        tag: ["活动", "309"]
      },
      {
        title: "清晨跑步攻略",
        posterUrl: "cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/swiper/image4.jpg",
        tag: ["99", "攻略"]
      },
      {
        title: "逛公园好去处",
        posterUrl: "https://img1.baidu.com/it/u=2852404479,2009840107&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400",
        tag: "49"
      },
      {
        title: "清晨跑步攻略",
        posterUrl: "https://img0.baidu.com/it/u=1281911112,1084861743&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
        tag: "109"
      },
    ],
    iconList: [
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/paihangbang.png',
        name: '排行榜',
        isAvailable: false,
        url: '/pages/rank/rank',
        editable: false,
      },
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/nengliang.png',
        name: '绩点能量',
        isAvailable: false,
        url: '/pages/rank/rank', // 没有URL，敬请期待
        editable: false,
      },
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/jilu.png',
        name: '最近记录',
        isAvailable: false,
        url: '/pages/rank/rank',
        editable: false,
      },
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/huodongliebiao.png',
        name: '活动列表',
        isAvailable: false,
        url: '/pages/rank/rank',
        editable: false,
      },
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/jifenshangcheng.png',
        name: '积分商城',
        isAvailable: false,
        url: '/pages/rank/rank',
        editable: false,
      },
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/weizhi.png',
        name: '校园地图',
        isAvailable: false,
        url: '/pages/rank/rank',
        editable: false,
      },
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/zhaocesuo.png',
        name: '周边旅游',
        isAvailable: false,
        url: '/pages/rank/rank',
        editable: false,
      },
      {
        icon: 'cloud://tfjkp-0ge80vu9ea710148.7466-tfjkp-0ge80vu9ea710148-1305195523/myjkp/checkinlisticon/zhaotingchechang.png',
        name: '生活团购',
        isAvailable: false,
        url: '/pages/rank/rank',
        editable: false,
      }
    ],


    longitude: 0, //地图经纬度
        latitude: 0, //地图经纬度
        positionList: [], //站点位置信息列表
  },

  onLoad() {
    console.log('首页打卡页面')
    const systemInfo = wx.getSystemInfoSync();
    this.setData({
      StatusBar: systemInfo.statusBarHeight,
      additionalOffset: (app.globalData.CustomBar - systemInfo.statusBarHeight) / 2
    });
  },

      /**导航到跑步详情页面。
     */
    startSport() {
      console.log('[run.js]开始------------------------------------------------------------------------------------')
      console.log('[run.js]用户开始运动')
      // 获取当前时间戳并保存到本地缓存
      const startTime = new Date().getTime();
      // 将开始时间保存到本地缓存
      wx.setStorageSync('startTime', startTime); 
      wx.navigateTo({
          url: '/pages/checkin/rundetails/rundetails',
      });
  },
















  onControlsToggle() {
    this.setData({
      showControls: false
    });
  },

  // toRun: function () {
  //   wx.navigateTo({
  //     url: '/pages/checkin/run/run',
  //   });
  // },

  // 点击项目的处理函数
  navigateToPage: function (e) {
    const item = e.currentTarget.dataset.item;  // 获取点击项的全部数据
    console.log('Clicked item:', item); // 输出点击的数据，便于调试

    // 判断是否有 URL 或者是否可编辑
    if (item.url && item.editable) {
      // 如果有 URL 且可编辑，则跳转页面
      console.log('Navigating to:', item.url); // 打印跳转的路径
      wx.navigateTo({
        url: item.url,
        success: function () {
          console.log('Navigation success');  // 如果跳转成功，输出日志
        },
        fail: function (err) {
          console.error('Navigation failed:', err);  // 如果跳转失败，输出错误信息
        }
      });
    } else {
      // 如果没有 URL 或不可编辑，则弹出提示
      const message = item.url ? `${item.name} 正在开发中~` : `${item.name} 还没有开发，敬请期待~`;
      wx.showToast({
        title: message,
        icon: 'none',
        duration: 2000
      });
    }
  }
});
